#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int sumNumbers(TreeNode* root, int n) {
        if (root == nullptr) return 0;
        n = n * 10 + root->val;
        if (root->left == nullptr && root->right == nullptr) return n;

        int ret = 0;
        ret += sumNumbers(root->left, n);
        ret += sumNumbers(root->right, n);
        return ret;
    }
    int sumNumbers(TreeNode* root) {
        int n = 0;
        return sumNumbers(root, n);

    }
};